package bairui.international.console.web.controller.finance.withdraw;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;

import bairui.international.model.domain.jpa.QTB_BranchCompanyWithdrawOrder;
import bairui.international.model.domain.jpa.TB_BranchCompanyWithdrawOrder;
import bairui.international.model.domain.jpa.TB_User;
import bairui.international.service.Service_BranchCompanyWithdrawOrder;

/**
 *
 * 列表
 *
 * @generated
 * 
 * @see STest_C_Finance_Withdraw_Page_Page 测试
 *
 */
@Controller
public class C_Finance_Withdraw_Page_Page
 extends SC_Finance_Withdraw_Page_Page 
{
	
	@Autowired private Service_BranchCompanyWithdrawOrder service_BranchCompanyWithdrawOrder;
	
	/**
	 * 分页列表
	 */
	@SuppressWarnings("serial")
	@Action(Page.class)
	@GetMapping(value=Page.RequestMappingValue, consumes=MediaType.APPLICATION_JSON_VALUE)
	public @FomatOutput @ResponseBody Object page(
		HttpServletRequest request
	) throws Exception {
		org.springframework.data.domain.Page<TB_BranchCompanyWithdrawOrder> page = service_BranchCompanyWithdrawOrder.page(
				it->filter(it, request),  
				Page.Output.page(request), 
				it->sort(it, request)
			);
		//
		return Page.Output.output(
				page.map(it->new Page.Output.Model(it) {
					private TB_User user;
					@Override protected void assign_before() {
						user = it.getBranchCompanyStaff().getUser();
					}
					@Override protected String assignRealName() {
						return user.getRealName();
					}
					@Override protected String assignPhone() {
						return user.getPhone();
					}
					@Override protected String assignNickName() {
						return user.getNickName();
					}
					@Override protected String assignAvatarUrl() {
						return user.getAvatarUrl();
					}
				})
			);
	}

	static Sort sort(QTB_BranchCompanyWithdrawOrder it, HttpServletRequest request) {
		return Page.Output.sort(it, request, new Page.Output.OrderExtends() {
			@Override public Sort gainRealName(Direction direction) {
				return sort(direction, it.branchCompanyStaff.user.realName);
			}
			@Override public Sort gainPhone(Direction direction) {
				return sort(direction, it.branchCompanyStaff.user.phone);
			}
			@Override public Sort gainNickName(Direction direction) {
				return sort(direction, it.branchCompanyStaff.user.nickName);
			}
			@Override public Sort gainAvatarUrl(Direction direction) {
				return sort(direction, it.branchCompanyStaff.user.avatarUrl);
			}
		});
	}

	static BooleanBuilder filter(QTB_BranchCompanyWithdrawOrder it, HttpServletRequest request) {
		return Page.Filter.query(it, request, new Page.Filter.FilterExtends() {
			@Override public Predicate gainRealName(String realName) {
				return it.branchCompanyStaff.user.realName.like("%" + realName + "%");
			}
			@Override public Predicate gainPhone(String phone) {
				return it.branchCompanyStaff.user.phone.like("%" + phone + "%");
			}
			@Override public Predicate gainNickName(String nickName) {
				return it.branchCompanyStaff.user.nickName.like("%" + nickName + "%");
			}
		});
	}
	

}
